export const getvar = (argu: string) => {
    //查询字符串并去掉开头的问号
    let qs = location.search.length > 0 ? location.search.substring(1) : ''
    //获取每一项
    let items = qs.length ? qs.split('&') : []
    let key = null,
        value = null
    for (let i = 0; i < items.length; i++) {
        key = decodeURIComponent(items[i].split('=')[0])
        value = decodeURIComponent(items[i].split('=')[1])
        if (key == argu) return value
    }
}
export const transformTime = (date: string | number | Date, dateed: string) => {
    var d = '',
        m = '',
        day = '',
        datetime = '',
        h = '',
        min = '',
        s = '',
        tod = '',
        tom = '',
        today = '';
    d = new Date(date)
    tod = new Date()
    m = d.getMonth() + 1 < 10 ? '0' + (d.getMonth() + 1) : d.getMonth() + 1
    tom = tod.getMonth() + 1 < 10 ? '0' + (tod.getMonth() + 1) : tod.getMonth() + 1
    day = d.getDate() < 10 ? '0' + d.getDate() : d.getDate()
    today = tod.getDate() < 10 ? '0' + tod.getDate() : tod.getDate()
    h = d.getHours() < 10 ? '0' + d.getHours() : d.getHours()
    min = d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes()
    s = d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds()
    if (dateed == 'minutesTwo') {
        if (d.getFullYear() == tod.getFullYear() && m == tom && day == today) {
            datetime = h + ':' + min
            return datetime
        } else {
            datetime = m + '-' + day
            return datetime
        }
    }
}
// 时间转化年月日
export const transformTimeTwo = (date: string | number | Date, dateed: string) => {
    var d = '',
        m = '',
        day = '',
        datetime = '',
        h = '',
        min = '',
        s = '';
    // dateFormat;
    // dateFormat = date.replace(/\-/g, '/')
    // dateFormat = date.replace(/\//g, '-')
    // d = new Date(dateFormat)
    // console.log(1111222);
    // console.log(date);

    d = new Date(date)
    m = d.getMonth() + 1 < 10 ? '0' + (d.getMonth() + 1) : d.getMonth() + 1
    day = d.getDate() < 10 ? '0' + d.getDate() : d.getDate()
    h = d.getHours() < 10 ? '0' + d.getHours() : d.getHours()
    min = d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes()
    s = d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds()
    if (dateed == 'date') {
        datetime = d.getFullYear() + '-' + m + '-' + day
        return datetime
    } else if (dateed == 'minutes') {
        datetime = d.getFullYear() + '-' + m + '-' + day + ' ' + h + ':' + min
        return datetime
    } else if (dateed == 'minutesdd') {
        datetime = d.getFullYear() + '/' + m + '/' + day + ' ' + h + ':' + min
        return datetime
    } else if (dateed == 'minutesTwo') {
        datetime = h + ':' + min
        return datetime
    } else {
        datetime = d.getFullYear() + '-' + m + '-' + day + ' ' + h + ':' + min + ':' + s
        return datetime
    }
}

// url 获取参数值
export const getQueryString = (name: string) => {
    const str = window.location.href
    const reg = /([^?&=]+)=([^&]+)/g // 分组捕获 两个子组
    const params: any = {}
    str.replace(reg, (_: any, k: string | number, v: any) => (params[k] = v))
    return params[name]
    //   var url = window.location.href; //获取url中"?"符后的字串
    //  if (url.indexOf("?") != -1) {    //判断是否有参数
    //     var str = url.substring(1); //从第一个字符开始 因为第0个是?号 获取所有除问号的所有符串
    //     var strs = str.split("=");   //用等号进行分隔 （因为知道只有一个参数 所以直接用等号进分隔 如果有多个参数 要用&号分隔 再用等号进行分隔）
    //     return strs[1];          //直接弹出第一个参数 （如果有多个参数 还要进行循环的）
    //  }
}
